package com.consumer.controller;


import com.entities.Payment;
import com.entities.ResponseEntity;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @program: springcloud
 * @description:
 * @author: zfy
 * @create: 2020-08-16 10:08
 */
@Controller
@ResponseBody
public class ConsumerConroller {
//    访问固定端口
//    public static  final String PAYMENT_URL="http://localhost:8001/";
//    访问服务名称   需要开启负载均衡@LoadBalanced
    public static  final String PAYMENT_URL="http://Cloud-provider-payment/";

    @Resource
    private RestTemplate restTemplate;
    @Resource
//    获取注册信息
    private DiscoveryClient discoveryClient;

    @GetMapping("com/consumer/payment/insert")
    public ResponseEntity<Payment> creat(Payment payment){
        return restTemplate.postForObject(
                PAYMENT_URL+"payment/insert",
                payment,
                ResponseEntity.class);
    }


    @GetMapping("com/consumer/payment/zk")
    public ResponseEntity<Payment> getPayment(@PathVariable("id") String id){
        return restTemplate.getForObject( PAYMENT_URL+"/payment/zk", ResponseEntity.class);

    }


}